      subroutine ireadgrd(nunit,ivar,i0,i1,j0,j1)
!
! reads 2d array from a grd file
!
      implicit none

      ! Input/output variables
      integer(4), intent(out) :: ivar(i0:i1,j0:j1)

      integer(4), intent(in) :: i0, i1
      integer(4), intent(in) :: j0, j1
      integer(4), intent(in) :: nunit

      ! Local variables
      real(8) :: xmin, xmax
      real(8) :: ymin, ymax
      integer(4) :: zmin, zmax

      integer(4) :: nx, ny
      integer(4) :: i, j
      integer(4) :: inperr

      character(len=4) :: dsaa


      read(nunit,'(a4)') dsaa
      read(nunit,*) nx,ny
      read(nunit,*) xmin,xmax
      read(nunit,*) ymin,ymax
      read(nunit,*) zmin,zmax


      do j = j0, j1
         read(nunit,fmt=1,iostat=inperr) (ivar(i,j),i=i0,i1)
         if (inperr /= 0) then
           write(*,*) 'Error in IREADGRD, ', 'iostat = ', inperr, &
           & ' j = ', j
           STOP
         endif
      enddo

1     format (<i1-i0+1>I8)
      return
      end
